import { smartTranslate as $t } from '@/lang';
export const useForm = (options = {}) => {
  const { formData, formItems, showSearch, formItemSpan } = options;
  const formConfig = computed(() => {
    // 如果没有表单项，返回空对象
    if (formItems.value.length === 0) return {};

    // 操作按钮
    const searchButtons = {
      folding: true,
      align: 'left',
      itemRender: {
        name: 'RaElButtonSetRender',
        props: {
          buttons: [
            {
              nativeType: 'submit',
              content: $t('common.action.search', '搜索'),
              type: 'primary',
              icon: 'Search',
            },
            {
              nativeType: 'reset',
              content: $t('common.action.reset', '重置'),
              type: 'info',
              icon: 'Refresh',
            },
          ],
        },
      },
    };

    // 表单配置
    return {
      span: formItemSpan.value,
      collapseStatus: !showSearch.value,
      titleOverflow: true,
      titleBold: true,
      data: formData.value,
      items: [...formItems.value, searchButtons],
    };
  });
  return { formConfig, formData, showSearch };
};
